{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "https://www.zhihu.com/question/558583427\n",
    "Python 如何循环三次输入不同的坐标值？\n",
    "\n",
    "Python中重要的内建异常类型：\n",
    "\n",
    "- Exception：常规错误的基类\n",
    "- AttributeError：对象没有这个属性\n",
    "- IOError：输入/输出操作失败\n",
    "- IndexError：序列中没有此索引(list index out of range)\n",
    "- KeyError：映射中没有这个键\n",
    "- NameError：未声明/初始化对象（没有属性）\n",
    "- SyntaxError：Python语法错误\n",
    "- SystemError：一般解释器系统错误\n",
    "- ValueError：串入无效的参数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[12. 23.]\n",
      " [67. 89.]\n",
      " [23. 67.]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "positions=np.zeros((3,2), np.float32)\n",
    "current_pos_idx = 0\n",
    "input_hint_txt = ['请输入第{}个坐标x值', '请输入第{}个坐标y值']\n",
    "while current_pos_idx < 6:\n",
    "    pos_idx = current_pos_idx//2\n",
    "    str = input(input_hint_txt[current_pos_idx%2].format(pos_idx+1))\n",
    "    try:\n",
    "        cur_val = float(str)\n",
    "        y = current_pos_idx%2\n",
    "        positions[pos_idx,y] = cur_val\n",
    "        current_pos_idx +=1\n",
    "    except Exception as e:\n",
    "        print(e)\n",
    "        print('您输入的内容不符合要求')\n",
    "print(positions)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'TypeError'>\n",
      "can only concatenate str (not \"int\") to str\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    s = 'test error'\n",
    "    i = 10\n",
    "    c = s+i\n",
    "except Exception as e:\n",
    "    print(type(e))\n",
    "    print(e)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.9.12 ('base')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "ad2bdc8ecc057115af97d19610ffacc2b4e99fae6737bb82f5d7fb13d2f2c186"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
